﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Bunian.Core.BusinessObjects"
                   assembly="Bunian.Core">

  <class name="IBeneficiary" table="Beneficiaries" lazy="false">

    <id name="Id" column="BeneficiaryId" unsaved-value="0">
      <generator class="native"/>
    </id>
    
    <bag name="BeneficiaryTenders" inverse="true" generic="true" cascade="all-delete-orphan">
      <key column="BeneficiaryId"/>
      <one-to-many class="Tender" />
    </bag>

    <joined-subclass name="Child" table="FamilyMembers">

      <key column="BeneficiaryId" />

      <many-to-one name="ContactInfo" column="PersonId" class="Contact" />
      <many-to-one name="Family" column="FamilyId" class="Family" />

      <property name="Description" column="Description" type="System.String" />

    </joined-subclass>

    <joined-subclass name="Family" table="Families">

      <key column="BeneficiaryId" />
      
      <property name="BaseIncome" column="BaseIncome" type="System.Decimal"/>
      <property name="ProviderKinship" column="ProviderKinship" />
      
      <property name="Description" column="Description" type="System.String" />
      <property name="SourcesOfIncome" column="SourcesOfIncome" type="System.String" />

      <many-to-one name="Mother" column="MotherId" class="Contact" cascade="all" />
      <many-to-one name="Father" column="FatherId" class="Contact" cascade="all" />
      <many-to-one name="Provider" column="ProviderId" class="Contact" cascade="all" />
      <many-to-one name="ContactDetails" column="ContactDetailsId" class="Contact" cascade="all" />

      <bag name="FamilyMembers" inverse="true" generic="true" cascade="all">
        <key column="FamilyId"/>
        <one-to-many class="Child" />
      </bag>

    </joined-subclass>
   
  </class>
</hibernate-mapping>